<!--
 * @Author: ljc
 * @Date: 2023-05-05 14:09:40
 * @LastEditors: g05047
 * @LastEditTime: 2023-06-15 16:56:17
 * @Description: 任务详情规则列表
-->

<template>
  <div style="height: 100%;">
    <rk-grid ref="taskDetilRuleRef"
      :data="ruleList"
      :boxConfig='false'
      :columns="tableColumns"
      :pagerConfig='false'
      :spanMethod="mergeRowMethod">
    </rk-grid>
  </div>
</template>
<script setup>
import { EXPERT_SCORE_STATUS } from '@/enums/enums-expert.js'

const props = defineProps({
  ruleList: { type: Array, default: [] }
})
const taskDetilRuleRef = ref(null)
const tableColumns = ref([
  { field: 'entryLev1', title: '一级条目', width: 120, align: 'center', },
  { field: 'entryLev2', title: '二级条目', width: 350, align: 'left', },
  { field: 'reviewDesc', title: '评审内容', width: 700, align: 'left', },
  {
    field: 'scoreType', title: '评分选项', width: 100, align: 'center', slots: {
      default: ({ row }) => {
        return row.scoreType ? EXPERT_SCORE_STATUS.options[row.scoreType].label : ""
      }
    }
  },
  { field: 'reviewStandard', title: '评审标准', width: 120, align: 'center', },
  { field: 'remark', title: '备注', width: 120, align: 'left', },
])
// 表格合计行
const mergeRowMethod = ({ row, _rowIndex, column, visibleData }) => {
  const fields = ['scoreType', 'entryLev1', 'entryLev2']
  const cellValue = row[column.field]
  if (cellValue && fields.includes(column.field)) {
    const prevRow = visibleData[_rowIndex - 1]
    let nextRow = visibleData[_rowIndex + 1]
    if (prevRow && prevRow[column.field] === cellValue) {
      return { rowspan: 0, colspan: 0 }
    } else {
      let countRowspan = 1
      while (nextRow && nextRow[column.field] === cellValue) {
        nextRow = visibleData[++countRowspan + _rowIndex]
      }
      if (countRowspan > 1) {
        return { rowspan: countRowspan, colspan: 1 }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.w-200px {
  width: 200px;
}
</style>